def solution(n: int, a: list) -> list:
    # PLEASE DO NOT MODIFY THE FUNCTION SIGNATURE
    # write code here
    l = []

    while True:
        l.append(a.pop(0))
        e = a.pop(0)
        a.append(e)
        if len(a) == 1:
            l.extend(a)
            break
    return l


if __name__ == '__main__':
    print(solution(n=5, a=[5, 3, 2, 1, 4]) == [5, 2, 4, 1, 3])
    print(solution(n=4, a=[4, 1, 3, 2]) == [4, 3, 1, 2])
    print(solution(n=6, a=[1, 2, 3, 4, 5, 6]) == [1, 3, 5, 2, 6, 4])